package windows;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSeparator;
import javax.swing.JSpinner;
import javax.swing.JTextField;

import sun.management.snmp.util.JvmContextFactory;

import coordinators.CoordinatorInsumos;

public class ManageInsumosCreate extends JPanel implements ActionListener
{
	private static final long serialVersionUID = 1L;
	private JButton btnOk;
	private JButton btnAddInsumos;

	CoordinatorInsumos coordinatorInsumos;

	private JComboBox cboNamesInsumos;

	private JLabel lblNameInsumo;
	private JLabel lblCodInsumo;


	private JTextField txtNameInsumo;
	public  JTextField txtCodInsumo;


	private JSpinner spnAmount;

	private JSeparator Separator;



     public  ManageInsumosCreate()
	{
		setLayout(null);

		coordinatorInsumos = new CoordinatorInsumos(this);



		/***************************JButton**************************************/
		btnOk= new JButton("Guardar");
		btnOk.setBounds(170, 270, 100, 20);
		btnOk.addActionListener(this);
		add(btnOk);

		btnAddInsumos= new JButton(" Agregar Insumo ");
		btnAddInsumos.setBounds(170, 220, 150, 20);
		btnAddInsumos.addActionListener(this);
		add(btnAddInsumos);


		/*********************************JSeparator***********************************************/


		Separator =new JSeparator();
		Separator.setBounds(50, 100, 360,5 );
		add(Separator);

		spnAmount=new JSpinner();
		spnAmount.setBounds(300, 150, 40, 25);
		spnAmount.setEnabled(false);
		add(spnAmount);

	    /******************************JLabel**********************************/

		lblCodInsumo=new JLabel("Codigo:");
		lblCodInsumo.setBounds(50, 15, 150, 25);
		add(lblCodInsumo);

		lblNameInsumo = new JLabel("Nombre Lista:");
		lblNameInsumo.setBounds(50, 50, 150, 25);
		add(lblNameInsumo);

		cboNamesInsumos= new JComboBox();
		cboNamesInsumos.setBounds(100,150,150,25);
		add(cboNamesInsumos);

		cboNamesInsumos.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Harina", "Leche", "Azucar", "Huevos" , "Colorantes", "Saborizantes", "Fresas", "Uvas Pasas"}));


		/****************************JTextArea*************************************/
		txtNameInsumo = new JTextField();
		txtNameInsumo.setBounds(200, 50, 150, 20);
		add(txtNameInsumo);

		txtCodInsumo = new JTextField();
		txtCodInsumo.setBounds(200, 15, 150, 20);
		txtCodInsumo.setEditable(false);
		add(txtCodInsumo);


		/*******************************************************/

		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		setBounds((screenSize.width-664)/2, (screenSize.height-456)/2, 670, 310);
	}

	public void actionPerformed(ActionEvent e)
	{


		/*ArrayList<RelationInsumoAmoutn> listInsumos;
		listInsumos = new ArrayList<RelationInsumoAmoutn>();

		if(e.getSource()== btnOk)
		{
			if(rdoSugar.isSelected())
			{
				if(!spnSugar.getValue().toString().equals("0"))
				{
					//System.out.println(lblSugar.getText()+ ""+spnSugar.getValue());
					listInsumos.add(new RelationInsumoAmoutn(lblSugar.getText(),spnSugar.getValue()));
				}
			}

			if(rdoColoring.isSelected())
			{
				if(!spnColoring.getValue().toString().equals("0"))
				{
					//System.out.println(lblColoring.getText()+ ""+spnColoring.getValue());
					listInsumos.add(new RelationInsumoAmoutn(lblColoring.getText(),spnColoring.getValue()));
				}
			}
			if(rdoEgg.isSelected())
			{
				if(!spnEgg.getValue().toString().equals("0"))
				{
					//System.out.println(lblEgg.getText()+ ""+spnEgg.getValue());
					listInsumos.add(new RelationInsumoAmoutn(lblEgg.getText(),spnEgg.getValue()));
				}
			}
			if(rdoFlour.isSelected())
			{

				if(!spnFlour.getValue().toString().equals("0"))
				{
					//System.out.println(lblFlour.getText()+ ""+spnFlour.getValue());
					listInsumos.add(new RelationInsumoAmoutn(lblFlour.getText(),spnFlour.getValue()));
				}
			}
			if(rdoMilk.isSelected())
			{
				if(!spnMilk.getValue().toString().equals("0"))
				{
					//System.out.println(lblMilk.getText()+ ""+spnMilk.getValue());
					listInsumos.add(new RelationInsumoAmoutn(lblMilk.getText(),spnMilk.getValue()));
				}
			}
			if(rdoRaisin.isSelected())
			{
				if(!spnAmount.getValue().toString().equals("0"))
				{
					//System.out.println(lblRaisin.getText()+ ""+spnRaisin.getValue());
					//listInsumos.add(new RelationInsumoAmoutn(lblRaisin.getText(),spnRaisin.getValue()));
				}
			}
			if(rdoSabor.isSelected())
			{
				if(!spnSabor.getValue().toString().equals("0"))
				{
					//System.out.println(lblSabor.getText()+ ""+spnSabor.getValue());
					listInsumos.add(new RelationInsumoAmoutn(lblSabor.getText(),spnSabor.getValue()));
				}
			}
			if(rdoStraberry.isSelected())
			{
				if(!spnStraberry.getValue().toString().equals("0"))
				{
					//System.out.println(lblStraberry.getText()+ ""+spnStraberry.getValue());
					listInsumos.add(new RelationInsumoAmoutn(lblStraberry.getText(),spnStraberry.getValue()));
				}
			}

			coordinatorInsumos.buyInsumos(txtNameInsumo.getText(),listInsumos);
		}*/


		if(e.getSource()==spnAmount)
		{
			spnAmount.setEnabled(true);
		}



	}

	public void clean()
	{
		txtNameInsumo.setText("");
		txtCodInsumo.setText("");
		spnAmount.setValue(0);

	}

}
